package com.example.administrator.exkotlin.base

import com.example.administrator.exkotlin.base.`object`.Animal

/***
 *
 * xxx.kt中的方法都是顶层方法（会被编译成静态方法）
 * */
class Collect {
    fun <T> getList(data: MutableList<T>): MutableList<T> {
        return data
    }

    fun <E> traverseList(list: MutableList<E>) {
        for (get in list) {
            println(get)
        }
    }

    fun normal_collet() {
        val arrayList = ArrayList<Animal>()
        arrayList.add(Animal("Dog"))
        arrayList.add(Animal())
        arrayList.add(Animal("Cat"))

        for (a in 0 until arrayList.size step 1) {
            println(arrayList[a].kind)
        }
    }

    fun testList() {
        val list = Collect().getList(mutableListOf(Animal("Dog"), Animal("Cat")))
        for (get in list) {
            println(get.kind)
        }
    }

    fun testSet() {
        val mutableSetOf = mutableSetOf<String>("num1", "num2", "num3")
        for (get in mutableSetOf) {
            println(get)
        }
    }

    fun testMap() {
        val mutableMapOf = mutableMapOf<String, Int>("num1" to 1, "num2" to 2, "num3" to 3)
        mutableMapOf["num4"] = 4
        for (map in mutableMapOf) {
            println(map.key)
            println(map.value)
        }

        for ((num, int) in mutableMapOf) {
            println("num " + num + "int " + int)
        }
    }


    fun arry() {
        arrayOf("test")
        val arr = Array<Int>(5) { a: Int -> a }
        for (i in 0 until arr.size) {
            arr[i] = i
        }
        for (i in 0 until arr.size) {
            println(arr[i])
        }
    }


}